package com.deluxelx.soul.inn.service.nav.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.deluxelx.soul.inn.bean.nav.NavBar;
import com.deluxelx.soul.inn.common.util.RedisUtil;
import com.deluxelx.soul.inn.mapper.nav.NavMapper;
import com.deluxelx.soul.inn.service.nav.NavService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.deluxelx.soul.inn.common.constant.IndexType.NAVBAR_CACHE_KEY;

/**
 * 首页导航服务实现类
 *
 * @author: zihao.liao
 * @date: 2024/1/15 17:18
 */
@Service
public class NavServiceImpl implements NavService {

    @Resource
    private NavMapper navMapper;

    @Resource
    private RedisUtil redisUtil;

    @Override
    public List<NavBar> fetchNavBarList() {
        String key = NAVBAR_CACHE_KEY;
        List<NavBar> navBarListCache = redisUtil.lGetAll(key, NavBar.class);
        if (CollectionUtil.isNotEmpty(navBarListCache)) {
            return navBarListCache;
        }
        List<NavBar> navBarList = navMapper.selectList(null);
        redisUtil.lSet(key, navBarList);
        return navBarList;
    }
}
